import { defineStore } from 'pinia'
import * as PIXI from 'pixi.js'

const useDiydataStore = defineStore('diydata', {
  state: () => ({
    visible: false, // 是否显示 // TODO 设置默认是否显示
    container: null as PIXI.Container | null, // 容器
    data: {} as Record<string, []>, // 数据
    categoryMap: new Map<string, number>(), // 类别对应的PIXI容器UID
  }),
  actions: {
    async init() {
      const request = await window.api.readDiyData()
      this.data = request.data as Record<string, []>
    },
    setContainer(container: PIXI.Container) {
      this.container = container
    },
    show() {
      this.container!.visible = true
    },
    hidden() {
      this.container!.visible = false
    },
    setVisible(visible: boolean) {
      this.visible = visible
    },
    setCategoryMap(key: string, container: PIXI.Container) {
      this.categoryMap.set(key, container.uid)
    },
    getCategoryMap(key: string) {
      return this.categoryMap.get(key)!
    },
  },
})

export default useDiydataStore
